package thinkingJava.chapter18;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GZIPcompress {
	public static void main(String[] args) throws IOException {
//		if (args.length == 0) {
//			System.exit(1);
//		}
		BufferedReader br = new BufferedReader(
				new FileReader("test2.txt"));
		BufferedOutputStream out = new BufferedOutputStream(
				new GZIPOutputStream(new FileOutputStream("test.gz")));
		System.out.println("writing file");
		int c;
		while ((c = br.read()) != -1) {
			out.write(c);
		}
		br.close();
		out.close();
		System.out.println("reading file");
		BufferedReader br2 = new BufferedReader(
				new InputStreamReader(
						new GZIPInputStream(
								new FileInputStream("test.gz"))));
		String s;
		while ((s = br2.readLine()) != null) {
			System.out.println(s);
		}
	}
}
